<?php include dirname(__FILE__).'/common/header.php'; ?>

<?php include dirname(__FILE__).'/common/menu.php'; ?>

var attr = {};
attr.group_level = <?php echo $group_level ?>;

/*
| -------------------------------------------------------------------
|  List Grid
| -------------------------------------------------------------------
*/
list.grid = new ZM.EditorGridPanel({
	tbar:[{
		text:'新建角色',
		cls:'btn-show',
		hidden:!Ext.permission['group/createGroup'.toLowerCase()],
		iconCls:'icon-create',
		handler:function() {
			var frm = new ZM.FormPanel({
				url:list.baseUrl + 'group/createGroup',
				keySubmit:false,
				success:function(res) {
					ZM.bo.msg('success',res.detail);
					list.grid.store.load();
					win.close();
				},
				items:[{
					xtype:'textfield',
					name:'group_name',
					fieldLabel:'名称',
					allowBlank:false
				}]
			});
			var win = new ZM.PopUp({
				title:'新建角色',
				type:'s',
				items:frm
			});
			win.show();
		}
	}],
	url: list.baseUrl + 'group/getGroupList',
	columns:[
		{header:'ID',dataIndex:'group_id',hidden:true},
		{header:'角色',dataIndex:'group_name',width:120},
		{header:'权限',dataIndex:'action_count'},
		{header:'级别',xtype:'sortcolumn',hidden:!Ext.pm('group/editGroupLevel'),dataIndex:'group_level',dataId:'group_id',url:list.baseUrl+'group/editGroupLevel'},
		{header:'操作',dataIndex:'',renderer:function(val,m,r) {
			str = '';
			if(r.json.group_level <= attr.group_level) {
				str += Ext.rd('编辑','fireEdit',r,'group/editGroup');
				str += Ext.rd('编辑权限','fireEditAction',r,'group/getGroupActionTree');
			}
			return str;
		}
	}]
});
/*
| -------------------------------------------------------------------
|  List Grid Action
| -------------------------------------------------------------------
*/
list.grid.fireEdit = function(r) {
	var r = r.json;
	var win = new ZM.PopUp({
		title:'编辑系统角色['+r.group_name+']',
		type:'s',
		items:new ZM.FormPanel({
			url:list.baseUrl + 'group/editGroup',
			params:{group_id:r.group_id},
			keySubmit:false,
			success:function(res) {
				ZM.bo.msg('success',res.detail);
				list.grid.store.load();
				win.close();
			},
			items:[{
				xtype:'textfield',
				name:'group_name',
				fieldLabel:'名称',
				allowBlank:false,
				value:r.group_name
			}]
		})
	}).show();
}

list.grid.fireEditAction = function(r) {
	var r = r.json;
	var actionTree = new ZM.TreePanel({
		url: list.baseUrl + 'group/getGroupActionTree',
		baseParams:{group_id:r.group_id},
		name:'group_action',
        paramName:'value',
        title:false,
		columns:[
			{header:'名称',dataIndex:'title',width:300}
		]
    });
	var win = new ZM.PopUp({
		title:'编辑['+r.group_name+']权限',
		type:'m',
		items:{
			xtype:'formpanel'
			,url: list.baseUrl + 'group/editGroupAction'
			,params:{group_id:r.group_id}
			,items:actionTree
			,layout:'fit'
			,success:function(res) {
				ZM.bo.msg('成功!',res.detail);
				list.grid.store.reload();
			}
		}
	}).show();
}
<?php include dirname(__FILE__).'/common/layout.php'; ?>
list.grid.store.load();
<?php include dirname(__FILE__).'/common/footer.php'; ?>